<?php  
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2011-     Laurent Luyssen   <big.lol13@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ 

include_once("includes/db.inc");
include_once("includes/functions.inc");
session_start();
include_once("includes/session.inc");

ControleAcces("pret_out.php", null, null,$user_id, session_id());
if(!$user_id)
	exit;

include ("includes/header.inc");

$id = $_GET['id'];
$borrower = $_GET['borrower'];

if (!isset($id) || ($id < 0))
{
   echo "<center><H2>";
   echo _("Veuillez choisir un livre !");
   echo "</H2></center>";
} 
else {
	// Check if book is already borrowed
	$b = get_borrower($id);
	if ($b){
	   echo "<center><H2>";
	   echo _("D&eacute;j&agrave; emprunt&eacute; par ");
	   echo $b['emprunteur']."</H2></center>";
	   exit();
	}
	
	if (!isset($borrower) || ($borrower == '') ) {
		$row = get_book($id);
		if (!$row) {
			print "PROBLEME : " .biblio_db_error();
			exit(); 
		}
		$liv_nom = $row['nom'];
		$liv_auteur = $row['auteur'];

		echo "<center><H1>Pr&ecirc;t de livre</H1>";
		echo "<H3><a href=\"resume.php?id=$id\" title=\"Details\">$liv_nom</a></H3>";
		echo "<i>$liv_auteur</i>";
		if (file_exists("images/covers/$id.jpg"))
			echo "<img src=images/covers/$id.jpg align=right>";
		echo '<Form action="pret_out.php" method="GET"><BR/>';
		echo _("Emprunteur :");
		echo '<input type="text" name="borrower" /><br/>';
		echo '<input type="hidden" name="id" value="'.$id.'"/><br/>';
		echo '<input type="submit" value="OK" /></form></center>';
	}
	else {
		$date_out = date("Y-m-d");
		$requete = "INSERT INTO prets2 (livre_Id, date_out, emprunteur) VALUES ($id, \"$date_out\", \"$borrower\")" ;
		$resultat = biblio_db_query($requete);
		if (!resultat) {
			print "PROBLEME : " .biblio_db_error();
			exit();
        }
       	echo "<center><img src=\"images/out.png\"><BR/>";
       	echo "<H2><A HREF=\"javascript:self.close();\">OK</A></H2></center>";
	}
}
?>
   <br><br>
   <div>
   <span id=left-text>
   <A HREF="javascript:self.close();">
   <?php echo _("Fermer"); ?>
   </A></span>
   </div>
   <br>
   <?php
   include("includes/footer.inc");
   exit;


?>
